package weaver.interfaces.jjy.duss.action;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/*
*@Description: 当在“总部审批”节点，被“退回”时，根据主表中的“人事范围编码”、“年份”、“节日类型”或“人事范围编码”、“年份”、“节日类型”、“部门编码”（看人事范围的值是否等于“8004” 或“8007” 或“ZB01”）；将uf_jbfxfhz中的“zt”字段改为0；
* 并将uf_jbfxfhz中的BMSBJRJBF、BMSBXJJBF清空；将uf_jbfxfmx中的GRSBJRJBF、GRSBXJJBF清空；
*@Author: Dusongsong
*@Date: 2019/12/24
*/
public class WeaHRjbfhtAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        RecordSet rs2 = new RecordSet();
        BaseBean baseBean = new BaseBean();
        String requestid = requestInfo.getRequestid();
        baseBean.writeLog("请求ID" + requestid);
        baseBean.writeLog("调用: WeaHRjbfhtAction");
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        rs.executeQuery("select * from " + tablename + " where requestid=?", requestid);
        baseBean.writeLog("select * from " + tablename + " where requestid=" + requestid);
        rs.next();
        String mainid = Util.null2String(rs.getString("id"));//外键
        String werks = Util.null2String(rs.getString("werks"));//人事范围编码
        String bmbm = Util.null2String(rs.getString("bmbm"));//部门编码
        String gjahr= Util.null2String(rs.getString("gjahr"));//年份
        String jrlx= Util.null2String(rs.getString("jrlx"));//假期类型
        String STATE = "0";
        String message = "";
        if ("8004".equals(werks) || "8007".equals(werks) || "ZB01".equals(werks)) {
            //更新明细表
            String SQL1 = "select grsbjrjbf,grsbxjjbf  from " + tablename + "_dt1 where mainid='"+mainid+"' and werks='"+werks+"' and bmbm='"+bmbm+"' and gjahr='"+gjahr+"' and jrlx='"+jrlx+"'";
            rs2.execute(SQL1);
            baseBean.writeLog(SQL1);
            while (rs2.next()){
                String updateSQL1 = "update uf_jbfmxb set grsbjrjbf='' ,grsbxjjbf= '' where  werks='" + werks + "' and bmbm='" + bmbm + "' and gjahr='" + gjahr + "' and jrlx='" + jrlx + "'";
                rs2.executeUpdate(updateSQL1);
                baseBean.writeLog("执行语句：" + updateSQL1);
            }
            //更新汇总表
            String updateSQL = "update uf_jbfhzb set bmsbjrjbf='',bmsbxjjbf='',zt='" + STATE + "' where werks='" + werks + "' and bmbm='" + bmbm + "' and gjahr='" + gjahr + "' and jrlx='" + jrlx + "'";
            rs.executeUpdate(updateSQL);
            baseBean.writeLog("调用SQL" + updateSQL);

        }else {
            //更新明细表
            String SQL1 = "select grsbjrjbf,grsbxjjbf  from " + tablename + "_dt1 where mainid='"+mainid+"' and werks='"+werks+"' and gjahr='"+gjahr+"' and jrlx='"+jrlx+"'";
            baseBean.writeLog(SQL1);
            rs2.execute(SQL1);
            while (rs2.next()){
                String updateSQL1 = "update uf_jbfmxb set grsbjrjbf='' ,grsbxjjbf= '' where werks='" + werks + "' and gjahr='" + gjahr + "' and jrlx='" + jrlx + "'";
                rs2.executeUpdate(updateSQL1);
                baseBean.writeLog("执行语句：" + updateSQL1);
            }
            //更新汇总表
            String updateSQL = "update uf_jbfhzb set bmsbjrjbf='',bmsbxjjbf='',zt='" + STATE + "' where werks='" + werks + "' and gjahr='" + gjahr + "' and jrlx='" + jrlx + "'";
            rs.executeUpdate(updateSQL);
            baseBean.writeLog("调用SQL" + updateSQL);
        }
        return Action.SUCCESS;
    }
}

